<?php
namespace control;

/*
*已考试类
*/

class testedClass extends adIndexClass
{
    private const page = 'tested';
    private const title = '已考试';

    /*列表-查询条件*/
    public function home()
    {
        //生成查询表单
        $html =
            text(array("name" => "title", "title" => L('person.table.sjbt'))) .
            text(array("name" => "createTime",'class'=>'width200', 'laydate' => ['range' => '~'], "title" => L('person.table.kskssj'))) .
            select(array("name" => "state", "title" => L('person.table.zhuang_tai'), "option" => ['未开始','进行中']));
        //返回
        return $this->homeFun($this->search($html));
    }

    /*客户列表-查询结果*/
    public function homeSearch()
    {
        //like查询数组
        $like = array(
            "b.title" => $this->post('title'),//试卷标题
        );
        //全等查询数组
        $equal = array(
            "b.state" => '已发布',//状态
        );
        //过滤掉已交卷的试卷
        $and = " and a.stid = '{$this->control['stid']}' and a.isCommit = 1";
        if ($this->post('createTime')) {
            $and .=$this->timeComparison($this->post('createTime'), field: 'startTime');
        }
        switch ($this->post('state')) {
            case '未开始';
                $and .= "  and UNIX_TIMESTAMP(b.startTime) > UNIX_TIMESTAMP()";
                break;
            case '进行中';
                $and .= "  and UNIX_TIMESTAMP(b.startTime) <= UNIX_TIMESTAMP() and UNIX_TIMESTAMP(b.endTime) >= UNIX_TIMESTAMP()";
                break;
        }

        //获取查询结果
        $where = search(array("like" => $like, "=" => $equal)) . $and;
        $page = $this->page(array("table" =>" topic_answer_record as a join paper_library as b on a.paperId = b.id",'field'=>"a.*,b.name", "where" => $where, "order" => " a.time desc"));
        $tr[] = array(L('person.table.sjbt'), L('person.table.ksys'), L('person.table.de_fen'), L('person.table.zhuang_tai'), '开始考试时间', L('person.table.tjsj'), L('person.table.cao_zuo'));
        //获取记录
        foreach ($page['array'] as $array) {
            //列表控件
            $second = strtotime($array['commitTime']) - strtotime($array['startTime']);
            $second = $second > 0 ? $second : 0;
            $mx = "<span class='del-row-button' onclick=\"window.open('" . root . "control/adIndex.html?cla=paperManagement&fun=previewPaper&method=record&stid={$array['stid']}&id={$array['paperId']}')\">".L('person.table.see')."</span>";
            $tr[] = array($array['name'],$second,$array['score'],$array['state'], $array['startTime'], $array['commitTime'],$mx);
        }
        //控件
        $button = "";
        //返回
        $json['html'] = $page['hint'] . $button . "<form name='listForm'>" . space . $this->tableMany(array("tr" => $tr)) . "</form>" . $page['button'] . clear;
        return json_encode($json, 320);
    }

}

